<?
        require_once('../../Inc/Global.php');
        require_once('ConnectData.php');
        $result = GetConnectMeths();
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="../../ECommSite/ECommCss.css" />
<title>Connection Methods</title>
</head>
<body>
<div id="tableWrapper">
<table border="1">
                        <tr>
                                <th>Actions</th>
                                <th>Person ID</th>
                                <th>Category ID</th>
                                <th>Connection Value</th>
                        </tr>
       
        <? 
        	while($rs = $result->fetch_assoc()){ 
        		include 'Row.php';
        } ?>
       
</table>
</div>
<div>
<a href="EditConnectMeth.php"><b>Click here to add a new Connection Method.</b></a>
<br />
<input type="button" value="Go Back" onclick="window.location.href='http://cs.newpaltz.edu/~N00001387/WebClass/WebClass/DatabaseProject/'" />
</div>
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
	<script type="text/javascript">
		$(function(){
			$.get("Controller.php?action=new",function(data){
				$("#tableWrapper").append(data);
			});
			$("form").live('submit',function(){
				var form = $(this);
				$.post(form.attr('action'), form.serialize(), function(data){
					record_row = form.closest(".record_row");
					if(record_row.length == 0)
						$("table:eq(0)").append(data);
					else
						record_row.replaceWith(data);
				});
                                
				return false;
				
			})
		
			$('.edit_link').live('click',function(){
				var editlink = $(this);
				$.get("Controller.php?action=edit&id=" + editlink.attr('data-id'),function(data){
					editlink.closest("tr").find("td").hide();
					formTd = $("<td></td>")
						.attr("colspan",4)
						.html(data)
						.appendTo(editlink.closest("tr"));
					formTd.find("select").each(function(){
						$(this).val($(this).attr('data-value'));
					});
				});
			return false;
				});
			});
			$('.cancel_link').live('click',function(){
				$(this).closest(".record_row").find("td").show();
				$(this).closest("form").closest("td").detach();
				return false;
			});
			$('.delete_link').live('click',function(){
			record_row = $(this).closest(".record_row");
			$.post(this.href,function(data){
			if(data == 'Success')
			{
				record_row.hide('slow');
			}
			});
		return false;
	});
</script>
</body>
</html>

